#ifndef __CLASSREGOSTER_H__
#define __CLASSREGOSTER_H__

#include <string>
#include "ClassFactory.h"

class ClassRegister
{
public:
    ClassRegister(const string & className, create_object method)
    {
        // register class
        ClassFactory * factory = Singleton<ClassFactory>::instance();
        factory->register_class(className, method);
    }

    ClassRegister(const string & className, const string & fieldName, const string & fieldType,  size_t offset)
    {
        // register class
        ClassFactory * factory = Singleton<ClassFactory>::instance();       
        factory->register_class_field(className, fieldName, fieldType, offset);
    }
    
    // ClassRegister(const string & className, const string & methodName, uintptr_t method)
    // {
    //     // register class
    //     Singleton<ClassFactory>::instance()->register_class_method(className, methodName, method);
    // }
};

#define REGISTER_CLASS(className)           \
    Object * createObject##className()      \
    {                                       \
        Object * obj = new className();     \
        obj->set_class_name(#className);    \
        return obj;                         \
    }                                       \
    ClassRegister ClassRegister##className(#className, createObject##className)

#define REGISTER_CLASS_FIELD(className, fieldName, fieldType)   \
    className className##fieldName;                             \
    ClassRegister ClassRegister##className##fieldName(#className, #fieldName, #fieldType, (size_t)(&(className##fieldName.fieldName)) - (size_t)(&className##fieldName))

#define REGISTER_CLASS_METHOD(className, methodName)                                        \
    std::function<void(className *)> className##methodName##method = &className::methodName \
    ClassRegister ClassRegister##className##methodName(#className, #methodName, (uintptr_t)&(className##methodName##method))

#endif